home *** CD-ROM | disk | FTP | other *** search
/ PC Format (UK) 188 / 01-04 PC Format 188 [2006-06] DVD side 1_.iso / DiscContents / Workshops / Workshops_Games / Sphere / InstallSphere1.0.exe / games / FG_nosphere / scripts / targeting.js < prev    next >
Text File  |  2003-02-18  |  4KB  |  170 lines

  1. function targeter(current, type, infoStyle)
  2. {
  3.     this.current = current;
  4.     this.type = type;
  5.     this.all = false;
  6.     this.selection = 0;
  7.     switch (current)
  8.     {
  9.         case "Ally":
  10.             this.side = system.currentBattle.party;
  11.             break;
  12.         case "Enemy":
  13.             this.side = system.currentBattle.enemy;
  14.             break;
  15.     }
  16.     if (type == "Multiple" || type == "Multiple-Only")
  17.     {
  18.         this.all = true;
  19.         this.cloneSide();
  20.     }
  21.     else
  22.         this.target = new Array(this.side[0]);
  23.     this.done = false;
  24.     this.infoStyle = infoStyle;
  25.     this.oldStyle = "";
  26. }
  27.  
  28. targeter.prototype.draw = function()
  29. {
  30.     var coordinates = new Array();
  31.     if (this.target.length == 1)
  32.     {
  33.         coordinates = this.target[0].sprite.getCoordinates(this.target[0].x, this.target[0].y, true);
  34.         drawCursor(coordinates[0], coordinates[1]);
  35.     }
  36.     else
  37.     {
  38.         for (var i = 0; i < this.target.length; i ++)
  39.         {
  40.             drawCursor(this.target[i].x, this.target[i].y, true);
  41.         }
  42.     }
  43. }
  44.  
  45. targeter.prototype.control = function()
  46. {
  47.     if (this.infoStyle != undefined && this.infoStyle != system.currentBattle.infoStyle)
  48.     {
  49.         this.oldStyle = system.currentBattle.infoStyle;
  50.         system.currentBattle.infoStyle = this.infoStyle;
  51.     }
  52.     if (IsPress())
  53.     {
  54.         if (IsKeyPressed(KEY_UP))
  55.         {
  56.             if (!this.all)
  57.             {
  58.                 Press();
  59.                 if (this.selection == 0)
  60.                 {
  61.                     this.selection == this.side.length - 1;
  62.                 }
  63.                 else
  64.                     this.selection --;
  65.                 this.target = new Array(this.side[this.selection]);
  66.             }
  67.         }
  68.         else if (IsKeyPressed(KEY_DOWN))
  69.         {
  70.             if (!this.all)
  71.             {
  72.                 Press();
  73.                 if (this.selection == this.side.length - 1)
  74.                 {
  75.                     this.selection = 0;
  76.                 }
  77.                 else
  78.                     this.selection ++;
  79.                 this.target = new Array(this.side[this.selection]);
  80.             }
  81.         }
  82.         else if (IsKeyPressed(KEY_LEFT))
  83.         {
  84.             Press();
  85.             if (this.current == "Ally")
  86.             {
  87.                 this.current = "Enemy";
  88.                 this.selection = 0;
  89.                 this.side = system.currentBattle.enemy;
  90.                 if (this.all)
  91.                 {
  92.                     this.cloneSide();
  93.                 }
  94.                 else
  95.                     this.target = new Array(this.side[this.selection]);
  96.             }
  97.         }
  98.         else if (IsKeyPressed(KEY_RIGHT))
  99.         {
  100.             Press();
  101.             if (this.current == "Enemy")
  102.             {
  103.                 this.current = "Ally";
  104.                 this.selection = 0;
  105.                 this.side = system.currentBattle.party;
  106.                 if (this.all)
  107.                 {
  108.                     this.cloneSide();
  109.                 }
  110.                 else
  111.                     this.target = new Array(this.side[this.selection]);
  112.             }
  113.         }
  114.         if (IsKeyPressed(KEY_A) && IsKeyPressed(KEY_SHIFT))
  115.         {
  116.             if (this.type != "Single-Only" && this.type != "Multiple-Only")
  117.             {
  118.                 Press();
  119.                 if (!this.all)
  120.                 {
  121.                     //log.write("Select all");
  122.                     this.all = true;
  123.                     this.cloneSide();
  124.                 }
  125.                 else
  126.                 {
  127.                     //log.write("Select one");
  128.                     this.all = false;
  129.                     this.target = new Array(this.side[this.selection]);
  130.                 }
  131.             }
  132.         }
  133.         if (IsKeyPressed(system.accept) && !IsKeyPressed(KEY_SHIFT))
  134.         {
  135.             log.write("Targeting done");
  136.             this.done = this.target;
  137.         }
  138.         else if (IsKeyPressed(system.cancel) && !IsKeyPressed(KEY_SHIFT))
  139.         {
  140.             this.done = true;
  141.         }
  142.     }
  143.     if (this.done != false)
  144.     {
  145.         if (typeof this.done != "object")
  146.         {
  147.             return true;
  148.         }
  149.         else
  150.         {
  151.             if (this.oldStyle != "" && this.infoStyle != undefined)
  152.             {
  153.                 system.currentBattle.infoStyle = this.oldStyle;
  154.                 this.oldStyle = "";
  155.             }
  156.             return this.target;
  157.         }
  158.     }
  159.     else
  160.         return undefined;
  161. }
  162.  
  163. targeter.prototype.cloneSide = function()
  164. {
  165.     this.target = new Array(this.side.length);
  166.     for (var i = 0; i < this.side.length; i ++)
  167.     {
  168.         this.target[i] = this.side[i];
  169.     }
  170. }